package cn.webrx.t4;

import java.util.Random;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

public class Demo {
    public static void main(String[] args) {
        ExecutorService es = Executors.newFixedThreadPool(5);
        for (int i = 0; i < 15; i++) {
            es.submit(() -> {
                try {
                    Random rand = new Random();
                    TimeUnit.SECONDS.sleep(rand.nextInt(1, 10));
                } catch (Exception e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName());
            });
        }

        es.shutdown();
        System.out.println("main");


        //es.execute(() -> {
        //    System.out.println(Thread.currentThread().getName());
        //});
        //
        //es.execute(() -> {
        //    System.out.println(Thread.currentThread().getName());
        //});
        //
        //
        //es.execute(() -> {
        //    System.out.println(Thread.currentThread().getName());
        //});
        //
        //es.execute(() -> {
        //    try{
        //        TimeUnit.SECONDS.sleep(5);
        //    }catch(Exception e){
        //        e.printStackTrace();
        //    }
        //    System.out.println(Thread.currentThread().getName());
        //});
        //System.out.println("main");

    }
}
